package com.cyj.dream.middleware.blackwhitelist.enums;

import lombok.Getter;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 黑白名单类型枚举类
 * @BelongsProject: DreamChardonnay
 * @BelongsPackage: com.cyj.dream.middleware.blackwhitelist.enums
 * @Author: ChenYongJia
 * @CreateTime: 2021-09-15 14:11
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Getter
@ToString
public enum SysBlackWhiteEnum {

    /**
     * 枚举信息
     */
    IS_WHITE(0, "白名单"),
    IS_BLACK(1, "黑名单"),
    IS_PERMANENT(0, "永久性"),
    DIS_PERMANENT(1, "暂时性");

    private Integer code;
    private String message;

    SysBlackWhiteEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * Gets message.
     *
     * @param name the name
     * @return the message
     */
    public static String getMessage(String name) {
        for (SysBlackWhiteEnum item : SysBlackWhiteEnum.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    /**
     * Gets code.
     *
     * @param name the name
     * @return the code
     */
    public static Integer getCode(String name) {
        for (SysBlackWhiteEnum item : SysBlackWhiteEnum.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    /**
     * The entry point of application.
     * 校验重复的code值 (**可去除**)
     *
     * @param args the input arguments
     */
    public static void main(String[] args) {
        SysBlackWhiteEnum[] sysBlackWhiteEnums = SysBlackWhiteEnum.values();
        List<Integer> codeList = new ArrayList<>();
        for (SysBlackWhiteEnum sysBlackWhiteEnum : sysBlackWhiteEnums) {
            if (codeList.contains(sysBlackWhiteEnum.getCode())) {
                System.out.println(sysBlackWhiteEnum.getCode());
            } else {
                codeList.add(sysBlackWhiteEnum.getCode());
            }
        }
        System.out.println(SysBlackWhiteEnum.getMessage("SUCCESS"));
        System.out.println(SysBlackWhiteEnum.getCode("SUCCESS"));
    }

    public String message() {
        return this.message;
    }

}
